package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityPrizeDO;
import com.example.lotterysystem.dao.dataobject.PrizeDO;
import com.example.lotterysystem.service.enums.ActivityStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 奖品
 * User: Spider-Man
 * Date: 2025-09-11
 * Time: 14:52
 */
@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name,image_url,price,description) " +
            "values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int insert(PrizeDO prizeDO);//返回的是奖品id

    /**
     * 奖品数量
     */
    @Select("select count(1) from prize")
    int count();

    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    /**
     * 奖品id查询
     */
    @Select("<script>" +
            "select id from prize " +
            "where id in " +
            "<foreach item='item' collection='items' " +
            "open ='(' separator=',' close= ')'>" +
            "#{item}" +
            "</foreach>"+
            "</script>")
    List<Long> selectExistByPriceIds(@Param("items") List<Long> ids);

    /**
     * 根据奖品id列表获取到奖品信息
     */
    @Select("<script>" +
            "select * from prize " +
            "where id in " +
            "<foreach item='item' collection='items' " +
            "open ='(' separator=',' close= ')'>" +
            "#{item}" +
            "</foreach>"+
            "</script>")
    List<PrizeDO>batchSelectByIds (@Param("items") List<Long> ids);

    /**
     * 查询当前活动running状态的个数
     */
    @Select("select count(1) from activity_prize where activity_id = #{activityId} and status = #{status}")
    int countPrize(@Param("activityId") Long activityId,
                   @Param("status")String status);

    /**
     * 根据奖品id获取奖品信息
     * @param prizeId
     */
    @Select("select * from prize where id = #{id}")
    PrizeDO selectById(@Param("id") Long prizeId);
}
